//
//  KLRNCCustomView.m
//  KISSLOCK
//
//  Created by 华杨科技 on 2017/4/19.
//  Copyright © 2017年 陈宾鹏. All rights reserved.
//

#import "KLRNCCustomView.h"

@implementation KLRNCCustomView


- (instancetype)initWithFrame:(CGRect)frame Title:(NSString *)title textPlaceholder:(NSString *)placeholder btntitle:(NSString *)btntitle buttonHandler:(void (^)(UIButton *))buttonHandler {
    self = [super init];
    
    if (self) {
        
        self.frame = frame;
        
        //  布局子控件
        self.titleLB.text = title;
        //        self.titleLB.backgroundColor = [UIColor grayColor];
        
        self.inputBoxTF.placeholder = placeholder;
        self.inputBoxTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        //        self.inputBoxTF.backgroundColor = [UIColor brownColor];
        
        // 下面放一个白色的view
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 50)];
        [bgView addSubview:_titleLB];
        [bgView addSubview:_inputBoxTF];
        bgView.backgroundColor = [UIColor whiteColor];
        
        [self.sureBtn setTitle:btntitle forState:(UIControlStateNormal)];
        [self.sureBtn setBackgroundColor:[UIColor redColor]];
//        self.layer.masksToBounds = YES; // 一下作用相同都可以切圆角
        self.sureBtn.clipsToBounds = YES;
        self.sureBtn.layer.cornerRadius = 5;
        
        // 通过block把sureBtn 带出去
        buttonHandler(_sureBtn);
        
              // 添加到view上
        [self addSubview:bgView];
        [self addSubview:_sureBtn];
    }
    
    
    return self;

}

- (instancetype)initWithFrame:(CGRect)frame Title:(NSString *)title textPlaceholder:(NSString *)placeholder btntitle:(NSString *)btntitle btnMethod:(SEL)method {
    
    self = [super init];
    
    if (self) {
        
        self.frame = frame;
        
        //  布局子控件
        self.titleLB.text = title;
//        self.titleLB.backgroundColor = [UIColor grayColor];
        
        self.inputBoxTF.placeholder = placeholder;
        self.inputBoxTF.clearButtonMode = UITextFieldViewModeWhileEditing;
//        self.inputBoxTF.backgroundColor = [UIColor brownColor];
        
        // 下面放一个白色的view
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 50)];
        [bgView addSubview:_titleLB];
        [bgView addSubview:_inputBoxTF];
        bgView.backgroundColor = [UIColor whiteColor];
        
        [self.sureBtn setTitle:btntitle forState:(UIControlStateNormal)];
        [self.sureBtn setBackgroundColor:[UIColor redColor]];
        self.sureBtn.layer.masksToBounds = YES;
        self.sureBtn.layer.cornerRadius = 5;
        
        
        // button点击事件
        [self.sureBtn addTarget:self action:method forControlEvents:(UIControlEventTouchUpInside)];
        
        // 添加到view上
        [self addSubview:bgView];
        [self addSubview:_sureBtn];
    }
    
    
    return self;
}

// 在该方法中设置子控件的frame
- (void)layoutSubviews {
    [super layoutSubviews];
    
}

// 子控件setter方法
- (UILabel *)titleLB {
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)];
    }
    return _titleLB;
}

- (UITextField *)inputBoxTF {
    if (!_inputBoxTF) {
        _inputBoxTF = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, self.frame.size.width - 100 - 10, 50)];
    }
    return _inputBoxTF;
}

- (UIButton *)sureBtn {
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _sureBtn.frame = CGRectMake(50, 100, self.frame.size.width - 100 , 50);
    }
    return _sureBtn;
}
@end
